package com.application.Activity;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.application.Controller.ActivityController;
import com.application.outdoor.InvoikeServices.HeThongInvoike;
import com.application.outdoor.adapter.TinNhanAdapter;
import com.application.outdoor.pojo.TinNhanPOJO;

public class od_TinNhanActivity extends Activity {
	ArrayList<TinNhanPOJO> lstTinNhan;
	ListView lvTinNhan;
	TinNhanAdapter adapter;
	Button btnXoaHet;
	TextView txtSoTinNhan;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.od_activity_tin_nhan);		
		ActivityController.arrActivity.add(this);
		lvTinNhan = (ListView) findViewById(R.id.lvTinNhan);
		lvTinNhan.setSelected(true);
		btnXoaHet=(Button)findViewById(R.id.btnXoaHet);
		txtSoTinNhan=(TextView)findViewById(R.id.txtSoTinNhan);
		getTinNhan();
		adapter = new TinNhanAdapter(this, lstTinNhan);
		lvTinNhan.setAdapter(adapter);
		
		btnXoaHet.setVisibility(View.GONE);
		if(lstTinNhan!=null&&lstTinNhan.size()>0){
			txtSoTinNhan.setText("Có tất cả "+lstTinNhan.size()+" tin nhắn");
		}else{
			txtSoTinNhan.setText("Không có tin nhắn nào!");
		}
	}


	private void getTinNhan() {
		try {
			String data =new  HeThongInvoike().layTinNhan(CommonUtilities.nguoiDung.getTenDangNhap());
			lstTinNhan = TinNhanPOJO.parseArray(data);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
